from PySide2 import QtGui
from PySide2.QtWidgets import *
from PySide2.QtGui import QColor, QFont


class Logger:

    logs: QTextEdit
    """日志显示控件 .append()增加日志"""

    def __new__(cls, *args, **kwargs):
        if not hasattr(cls, "_instance"):
            cls._instance = super().__new__(cls, *args, **kwargs)
            print("第一次创建EData")
        return cls._instance

    def bindOuttext(self, logs: QTextEdit):
        self.logs = logs

    def logNotice(self, text: str):
        color = QColor(100, 100, 100)
        self.logs.setFontWeight(QFont.Normal)
        self.logs.setTextColor(color)
        self.logs.append(text)

    def logWarning(self, text: str):
        color = QColor(255, 125, 0)
        self.logs.setFontWeight(QFont.Normal)
        self.logs.setTextColor(color)
        self.logs.append(text)

    def logError(self, text: str):
        color = QColor(255, 0, 0)
        self.logs.setTextColor(color)
        self.logs.append(text)

    def logSuccess(self, text: str):
        color = QColor(0, 166, 24)
        self.logs.setFontWeight(QFont.Normal)
        self.logs.setTextColor(color)
        self.logs.append(text)

    def logAllDone(self, text: str):
        color = QColor(0, 125, 24)
        self.logs.setFontWeight(QFont.Bold)
        self.logs.setTextColor(color)
        self.logs.append(text)

    def clear(self):
        self.logs.clear()